<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Cache-Control" content="no-siteapp" />

    <title>利用bloom filter算法处理大规模数据过滤</title>
    <meta name="description" content="Bloom Filter是由Bloom在1970年提出的一种快速查找算法，通过多个hash算法来共同判断某个元素是否在某个集合内。可以用于网络爬虫的url重复过滤、垃圾邮件的过滤等等。它相比hash容器的一个优势就是，不需要存储元素的实际数据到容器中去来一个个的比较是否存在。只需要对应的位段来标记是否存在就行了，...">

    
    <meta name="keywords" content="tbox,bloom,filter,算法,大数据,过滤,tboox" /> 

    <!-- qq oauth -->
    <meta property="qc:admins" content="5211601217706727767255" />

    <!--icon -->
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" sizes="192x192" href="/static/img/nice-highres.png" />
	<link rel="apple-touch-icon-precomposed" href="/static/img/apple-touch-icon-57x57-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/img/apple-touch-icon-72x72-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/img/apple-touch-icon-114x114-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/img/apple-touch-icon-144x144-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="180x180" href="/static/img/retinahd_icon.png" />
	<meta name="msapplication-TileImage" content="/static/img/retinahd_icon.png" />
	
    <link rel="stylesheet" href=" /css/fontawesome/css/font-awesome.min.css ">
    <link rel="stylesheet" href=" /css/main.css ">
    <link rel="canonical" href="https://tboox.org/cn/2016/02/03/bloom-filter/">
    <link rel="alternate" type="application/rss+xml" title="TBOOX Open Source Project" href="https://tboox.org/feed.xml ">
    <link rel="alternate" hreflang="en" href="https://tboox.org/" />
    <link rel="alternate" hreflang="zh-Hans" href="https://tboox.org/cn/" />

    <!-- css -->
    <link href="/css/reward.css" rel="stylesheet" type="text/css"> 




    <script type="text/javascript">
    function isPC(){    
        var userAgentInfo = navigator.userAgent;  
        var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");    
        var flag = true;    
        for (var v = 0; v < Agents.length; v++) {    
            if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }    
        }    
        return flag;    
    }
    </script>

<!-- baidu ads -->



    <!-- baidu ads -->

</head>


  <body>

    <header id="top">
    <div class="wrapper">
        <a href="/cn" class="brand">TBOOX</a>
        <button id="headerMenu" class="menu"><i class="fa fa-bars"></i></button>
        <nav id="headerNav">
            <ul>
                <li>
                    
                    <a href="/?lang=0">
                    
                        <i class="fa fa-home"></i>English
                    </a>
                </li>

                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/project/">
                            
                        
                            <i class="fa fa-bookmark"></i>项目
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/archive/">
                            
                        
                            <i class="fa fa-archive"></i>归档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/category/">
                            
                        
                            <i class="fa fa-th-list"></i>分类
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/tag/">
                            
                        
                            <i class="fa fa-tags"></i>标记
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/docs/">
                            
                        
                            <i class="fa fa-book"></i>文档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="https://xmake.io/#/zh-cn/about/contact" target="_blank" >
                            
                        
                            <i class="fa fa-forumbee"></i>社区
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/donation/">
                            
                        
                            <i class="fa fa-heart"></i>捐助
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/about/">
                            
                        
                            <i class="fa fa-user"></i>关于
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            </ul>
        </nav>
    </div>
</header>



        <div class="page clearfix" post>
    <div class="left">
        <h1>利用bloom filter算法处理大规模数据过滤</h1>
        <div class="label">

            <div class="label-card">
                <i class="fa fa-calendar"></i>2016-02-03
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
            


<!-- <span class="point">•</span> -->
<span class="categories">
  <i class="fa fa-th-list"></i>
  
    
        <a href="/category/#tbox" title="Category: tbox" rel="category">tbox</a>
    
  

  <!-- <span class="point">•</span> -->
</span>


            </div>

            <div class="label-card">
            
<!-- <span class="point">•</span> -->
<span class="pageTag">
  <i class="fa fa-tags"></i>
  
    
        <!--a href="/tag/#tbox" title="Tag: tbox" rel="tag">tbox</a-->
        <a href="/cn/tag/#tbox" title="Tag: tbox" rel="tag">tbox</a>&nbsp;
    
        <!--a href="/tag/#bloom" title="Tag: bloom" rel="tag">bloom</a-->
        <a href="/cn/tag/#bloom" title="Tag: bloom" rel="tag">bloom</a>&nbsp;
    
        <!--a href="/tag/#filter" title="Tag: filter" rel="tag">filter</a-->
        <a href="/cn/tag/#filter" title="Tag: filter" rel="tag">filter</a>&nbsp;
    
        <!--a href="/tag/#%E7%AE%97%E6%B3%95" title="Tag: 算法" rel="tag">算法</a-->
        <a href="/cn/tag/#算法" title="Tag: 算法" rel="tag">算法</a>&nbsp;
    
        <!--a href="/tag/#%E5%A4%A7%E6%95%B0%E6%8D%AE" title="Tag: 大数据" rel="tag">大数据</a-->
        <a href="/cn/tag/#大数据" title="Tag: 大数据" rel="tag">大数据</a>&nbsp;
    
        <!--a href="/tag/#%E8%BF%87%E6%BB%A4" title="Tag: 过滤" rel="tag">过滤</a-->
        <a href="/cn/tag/#过滤" title="Tag: 过滤" rel="tag">过滤</a>
    
  

</span>

            </div>

        </div>
        <hr>
        <article itemscope itemtype="http://schema.org/BlogPosting">
        <p>Bloom Filter是由Bloom在1970年提出的一种快速查找算法，通过多个hash算法来共同判断某个元素是否在某个集合内。可以用于网络爬虫的url重复过滤、垃圾邮件的过滤等等。</p>

<p>它相比hash容器的一个优势就是，不需要存储元素的实际数据到容器中去来一个个的比较是否存在。
只需要对应的位段来标记是否存在就行了，所以想当节省内存，特别适合海量的数据处理。并且由于省去了存储元素和比较操作，所以性能也比基于hash容器的高了很多。</p>

<p>但是由于bloom filter没有去比较元素，只通过多个hash来判断唯一性，所以存在一定的hash冲突导致误判。误判率的大小由hash函数的个数、hash函数优劣、以及存储的位空间大小共同决定。</p>

<p>并且删除也比较困难，解决办法是使用其变种，带计数的bloom filter，这个这里就不多说了。</p>

<p>对于bloom filter算法的实现，相当简单：
首先分配一块固定的连续空间，大小是m个比特位（m/8+1个字节），然后再提供k个不同hash函数，同时对每个元素进行计算位索引。如果每个位索引对应的位都为1，则存在该元素，否则就是不存在。</p>

<p>可以看出，如果判断为不存在，那么肯定是不存在的，只有在判断为存在的时候，才会存在误判。</p>

<p>bloom filter主要的难点其实在于估算：
保证指定误判率的情况下，到底需要多少个hash函数，多少的存储空间。</p>

<p>首先来看下bloom filter的误判率计算公式：</p>

<p>假定有k个hash函数，m个比特位的存储空间，n个集合元素，则有误判率p：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    p = (1 - ((1 - 1/ m) ^ kn))^k ~= (1 - e^(-kn/m))^k
</code></pre>
</div>

<p>根据这个，官方给出了一个计算k的最优解公式，使其满足给定p的情况下，存储空间达到最小：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    k = (m / n) * ln2
</code></pre>
</div>

<p>把它带入概率公式得到：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    p = (1 - e ^-((m/nln2)n/m))^(m/nln2)
</code></pre>
</div>

<p>简化为：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    lnp = -m/n * (ln2)^2
</code></pre>
</div>

<p>因此，如果指定p，只需要满足如果公式，就可以得到最优解：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    s = m/n = -lnp / (ln2 * ln2) = -log2(p) / ln2
    k = s * ln2 = -log2(p)
</code></pre>
</div>

<p>理论值：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    p &lt; 0.1: k = 3.321928, m/n = 4.79
    p &lt; 0.01: k = 6.643856, m/n = 9.58
    p &lt; 0.001: k = 9.965784, m/n = 14.37
    p &lt; 0.0001: k = 13.287712, m/n = 19.170117
</code></pre>
</div>

<p>可以看出，这个确实能够在保证误判率的前提下，使其存储空间达到最小，但是使用的hash函数个数k
相对较多，至少也得4个，要满足p &lt; 0.001，需要10个才行，这个对于字符串hash的计算来讲，性能损耗相当大的，实际使用中根本没法接受。</p>

<p>因此我们需要另外一种推到公式，可以认为指定p和k的情况下，来计算空间使用s=m/n的大小，这样我们在实际使用的时候，灵活性就大大提高了。</p>

<p>下面来看下，我自己推到出来的公式，首先还是依据误判率公式：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    p = (1 - e^(-kn/m))^k
</code></pre>
</div>

<p>假定s=m/n，则有</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    p = (1 - e^(-k/s))^k
</code></pre>
</div>

<p>两边取导，得到：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    lnp = k * ln(1 - e^(-k/s))
</code></pre>
</div>

<p>交换k：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    (lnp) / k = ln(1 - e^(-k/s))
</code></pre>
</div>

<p>重新上e：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    e^((lnp) / k) = 1 - e^(-k/s)
</code></pre>
</div>

<p>化简：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    e^(-k/s) = 1 - e^((lnp) / k) = 1 - (e^lnp)^(1/k) = 1 - p^(1/k)
</code></pre>
</div>

<p>再求导：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    -k/s = ln(1 - p^(1/k))
</code></pre>
</div>

<p>得出：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    s = -k / ln(1 - p^(1/k))
</code></pre>
</div>

<p>假定<code class="highlighter-rouge">c = p^(1/k)</code>：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    s = -k / ln(1 - c)
</code></pre>
</div>

<p>利用泰勒展开式：<code class="highlighter-rouge">ln(1 + x) ~= x - 0.5x^2 while x &lt; 1</code> 化简得到：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    s ~= -k / (-c-0.5c^2) = 2k / (2c + c * c)
</code></pre>
</div>

<p>最后得出公式：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    c = p^(1/k)
    s = m / n = 2k / (2c + c * c)
</code></pre>
</div>

<p>假定有n=10000000的数据量，则有理论值：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>    p &lt; 0.1 and k = 1: s = m/n = 9.523810
    p &lt; 0.1 and k = 2: s = m/n = 5.461082
    p &lt; 0.1 and k = 3: s = m/n = 5.245850, space ~= 6.3MB
    p &lt; 0.1 and k = 4: s = m/n = 5.552045, space ~= 6.6MB

    p &lt; 0.01 and k = 1: s = m/n = 99.502488
    p &lt; 0.01 and k = 2: s = m/n = 19.047619
    p &lt; 0.01 and k = 3: s = m/n = 12.570636, space ~= 15MB
    p &lt; 0.01 and k = 4: s = m/n = 10.922165, space ~= 13MB

    p &lt; 0.001 and k = 1: s = m/n = 999.500250
    p &lt; 0.001 and k = 2: s = m/n = 62.261118
    p &lt; 0.001 and k = 3: s = m/n = 28.571429, space ~= 34MB
    p &lt; 0.001 and k = 4: s = m/n = 20.656961, space ~= 24.6MB

    p &lt; 0.0001 and k = 1: s = m/n = 9999.500025
    p &lt; 0.0001 and k = 2: s = m/n = 199.004975
    p &lt; 0.0001 and k = 3: s = m/n = 63.167063, space ~= 75.3MB
    p &lt; 0.0001 and k = 4: s = m/n = 38.095238, space ~= 45.4MB
    p &lt; 0.0001 and k = 5: s = m/n = 29.231432, space ~= 24.8MB
</code></pre>
</div>

<p>可以看到，在k=3的情况下，其实已经可以达到我们平常使用所能的接受范围内了，没必要非得
使用最优解，除非在空间使用极为苛刻的情况下，而且这个公式，针对程序空间使用的调整，更加的灵活智能。</p>

<p>特别提下，经过实测，如果每个hash的实现非常优质，分布很均匀的情况下，其实际的误判率比理论值低很多:</p>

<p>就拿TBOX的bloom filter的实现做测试，n=10000000：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>p &lt; 0.01 and k = 3的情况下，其实际误判率为：0.004965
p &lt; 0.001 and k = 3的情况下，其实际误判率为：0.000967
</code></pre>
</div>

<p>所以好的hash函数算法也是尤为的重要。</p>

<p>下面来看下TBOX提供的bloom filter的使用，用起来也是相当的方便：</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code>    <span class="c1">// 总的元素个数
</span>    <span class="n">tb_size_t</span> <span class="n">count</span> <span class="o">=</span> <span class="mi">10000000</span><span class="p">;</span>

    <span class="cm">/* 初始化bloom filter
     *
     * TB_BLOOM_FILTER_PROBABILITY_0_01: 预定义的误判率，接近0.01
     * 注：由于内部使用位移数来表示：1 / 2^6 = 0.015625 ~= 0.01
     * 所以实际传入的误判率，有可能稍微大一点，但是还是相当接近的
     *
     * 3：为k值，hash函数的个数，最大不超过15个
     *
     * count：指定的元素规模数
     *
     * tb_item_func_long()：容器的元素类型，主要是用其内定的hash函数，如果要自定义hash函数，可以替换:
     *
     * tb_size_t tb_xxxxxx_hash(tb_item_func_t* func, tb_cpointer_t data, tb_size_t mask, tb_size_t index)
     * {
     *      // mask为hash掩码，index为第index个hash算法的索引
     *      return compute_hash(data, index) &amp; mask;
     * }
     *
     * tb_item_func_t func = tb_item_func_long();
     * func.hash = tb_xxxxxx_hash;
     *
     * 来进行
     */</span>
    <span class="n">tb_bloom_filter_ref_t</span> <span class="n">filter</span> <span class="o">=</span> <span class="n">tb_bloom_filter_init</span><span class="p">(</span><span class="n">TB_BLOOM_FILTER_PROBABILITY_0_01</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">tb_item_func_long</span><span class="p">());</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">filter</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">tb_size_t</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">count</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="c1">// 产生随机数
</span>            <span class="n">tb_long_t</span> <span class="n">value</span> <span class="o">=</span> <span class="n">tb_random</span><span class="p">();</span>
            
            <span class="c1">// 设置值到filter内，如果不存在，则返回tb_true表示设置成功
</span>            <span class="k">if</span> <span class="p">(</span><span class="n">tb_bloom_filter_set</span><span class="p">(</span><span class="n">filter</span><span class="p">,</span> <span class="p">(</span><span class="n">tb_cpointer_t</span><span class="p">)</span><span class="n">value</span><span class="p">))</span>
            <span class="p">{</span>
                 <span class="c1">// 添加元素成功，之前元素不存在
</span>                 <span class="c1">// 不会存在误判
</span>            <span class="p">}</span>
            <span class="k">else</span>
            <span class="p">{</span>
                 <span class="c1">// 添加失败，添加的元素已经存在
</span>                 <span class="c1">// 这里可能会存在误判
</span>            <span class="p">}</span>
            
            <span class="c1">// 仅仅判断元素是否存在
</span>            <span class="k">if</span> <span class="p">(</span><span class="n">tb_bloom_filter_get</span><span class="p">(</span><span class="n">filter</span><span class="p">,</span> <span class="p">(</span><span class="n">tb_cpointer_t</span><span class="p">)</span><span class="n">data</span><span class="p">)</span>
            <span class="p">{</span>
                 <span class="c1">// 元素已经存在
</span>                 <span class="c1">// 这里可能会存在误判
</span>            <span class="p">}</span>
            <span class="k">else</span>
            <span class="p">{</span>
                 <span class="c1">// 元素不存在
</span>                 <span class="c1">// 不会存在误判
</span>            <span class="p">}</span>
        <span class="p">}</span>
        
        <span class="c1">// 退出filter
</span>        <span class="n">tb_bloom_filter_exit</span><span class="p">(</span><span class="n">filter</span><span class="p">);</span>
    <span class="p">}</span>

    <span class="c1">// 常用预定义的误判率，也可以指定其他值，注：必须是位移数，而不是实际值
</span>    <span class="k">typedef</span> <span class="k">enum</span> <span class="n">__tb_bloom_filter_probability_e</span>
    <span class="p">{</span>
        <span class="n">TB_BLOOM_FILTER_PROBABILITY_0_1</span>         <span class="o">=</span> <span class="mi">3</span> <span class="c1">///!&lt; 1 / 2^3 = 0.125 ~= 0.1
</span>    <span class="p">,</span>   <span class="n">TB_BLOOM_FILTER_PROBABILITY_0_01</span>        <span class="o">=</span> <span class="mi">6</span> <span class="c1">///!&lt; 1 / 2^6 = 0.015625 ~= 0.01
</span>    <span class="p">,</span>   <span class="n">TB_BLOOM_FILTER_PROBABILITY_0_001</span>       <span class="o">=</span> <span class="mi">10</span> <span class="c1">///!&lt; 1 / 2^10 = 0.0009765625 ~= 0.001
</span>    <span class="p">,</span>   <span class="n">TB_BLOOM_FILTER_PROBABILITY_0_0001</span>      <span class="o">=</span> <span class="mi">13</span> <span class="c1">///!&lt; 1 / 2^13 = 0.0001220703125 ~= 0.0001
</span>    <span class="p">,</span>   <span class="n">TB_BLOOM_FILTER_PROBABILITY_0_00001</span>     <span class="o">=</span> <span class="mi">16</span> <span class="c1">///!&lt; 1 / 2^16 = 0.0000152587890625 ~= 0.00001
</span>    <span class="p">,</span>   <span class="n">TB_BLOOM_FILTER_PROBABILITY_0_000001</span>    <span class="o">=</span> <span class="mi">20</span> <span class="c1">///!&lt; 1 / 2^20 = 0.00000095367431640625 ~= 0.000001
</span>            
    <span class="p">}</span><span class="n">tb_bloom_filter_probability_e</span><span class="p">;</span>
</code></pre>
</div>


        </article>
        <hr>

        <!-- baidu ads -->
        

        <!-- reward -->
        <div style="text-align: center;">
            <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
              <span>赏</span>
            </button>
            <div id="QR" style="display: none;">
                <div id="wechat" style="display: inline-block">
                  <img id="wechat_qr" src="/static/img/weixin.png" alt="WeChat Pay"/>
                  <p>微信打赏</p>
                </div>
                <div id="alipay" style="display: inline-block">
                  <img id="alipay_qr" src="/static/img/alipay.png" alt="Alipay"/>
                  <p>支付宝打赏</p>
                </div>
            </div>
        </div>

        
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
        

        
        
            
        
            
            
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
        

        <div class="post-recent">
    <div class="pre">

        

        

        
        
        

        

        

        
        
        <p><strong>上一篇</strong> <a href="/cn/2016/01/30/welcome/">欢迎来到TBOOX开源项目!</a></p>
        
    </div>

    <div class="nex">

        

        

        
        
        <p><strong>下一篇</strong> <a href="/cn/2016/02/03/project-description/">xmake工程描述入门</a></p>
        
    </div>
</div>


        <h2 id="comments">评论</h2>
        






<div id="gitalk-container"></div>
<link rel="stylesheet" href="/css/gitalk.css">
<script src="/js/gitalk.min.js"></script>

<script>
const gitalk = new Gitalk({
  clientID: '73946dc1d9e2276ad0da',
  clientSecret: '12a3cb94361ba3ebc6ecb68cf80d592bfaa8106d',
  repo: 'tboox.github.io',
  owner: 'waruqi',
  admin: ['waruqi'],
  id: location.pathname,       
  language: 'zh-CN',
  distractionFreeMode: false  
})

gitalk.render('gitalk-container')
</script>





    </div>
    <button class="anchor"><i class="fa fa-anchor"></i></button>
    <div class="right">
        <div class="wrap">

            <!-- codefund ads -->
            

            <!-- Content -->
            <div class="side content">
                <div>
                    内容
                </div>
                <ul id="content-side" class="content-ul">
                    <li><a href="#english">English</a></li>
                    <li><a href="#similar_posts">相关文章</a></li>
                    <li><a href="#comments">评论</a></li>
                </ul>
            </div>


            <!-- baidu ads -->
            
            
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    链接
                </div>
                <ul class="content-ul">
                  <li><a href="http://github.com/waruqi/tbox">tbox</a></li>
                  <li><a href="http://www.xmake.io">xmake</a></li>
                  <li><a href="https://github.com/waruqi">github</a></li>
                </ul>
            </div> 

            <!-- xmake courses -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    xmake 入门课程
                </div>
                <a href="https://xmake.io/#/zh-cn/about/course" target="_blank">
                <img src="/static/img/xmake-course.png" alt="course" width="256" height="193">
                </a>
            </div>

            <!-- qqgroup -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    技术交流群（QQ）
                </div>
                <img src="/static/img/qqgroup.png" alt="qqgroup" width="256" height="284">
            </div> 

            <!-- google ads -->
            

            <!-- baidu ads -->
            

        </div>
    </div>

    <!-- baidu ads -->
    
</div>
<script>
/**
 * target _blank
 */
(function() {
    var aTags = document.querySelectorAll('article a:not([id])')
    for (var i = 0; i < aTags.length; i++) {
        aTags[i].setAttribute('target', '_blank')
    }
}());
</script>
<script src="/js/pageContent.js " charset="utf-8"></script>



    <footer class="site-footer">
    <div class="wrapper">
        <p class="description">
             Copyright (c) 2016-2020 tboox.org 
        </p>
        <p class="contact">
            
            <a href="https://github.com/waruqi" title="GitHub"><i class="fa fa-github" aria-hidden="true"></i></a> 
             
            
            <a href="mailto:waruqi@gmail.com" title="email"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> 
            
            
            <a href="https://twitter.com/waruqi" title="Twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a> 
            
            <a href="/feed.xml" title="feed"><i class="fa fa-feed" aria-hidden="true"></i></a> 
        </p>
        <p class="power">
            <span>
                Site powered by <a href="https://jekyllrb.com/">Jekyll</a> & <a href="https://github.com/Gaohaoyang">HyG</a> & <a href="https://pages.github.com/">Github Pages</a>.
            </span>
        </p>
    </div>
</footer>

    <div class="back-to-top">
    <a href="#top" class="scroll">
        <i class="fa fa-arrow-up" aria-hidden="true"></i>
    </a>
</div>

    <script src=" /js/main.js " charset="utf-8"></script>
    <script src=" /js/scroll.min.js " charset="utf-8"></script>
  </body>

</html>
